package savantConn;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class ImpalaTool {


  public static void main(String[] args) throws Exception {

    //这个地址填写自己的impala server地址,默认端口为21050
    //格式为jdbc:impala://[Host]:[Port]/[Schema];[Property1]=[Value];[Property2]=[Value];...
    //默认连接default库
    String connectionUrl = "jdbc:impala://172.16.4.5:21050";

    //使用4.1版本
    String jdbcDriverName = "com.cloudera.impala.jdbc41.Driver";
    //简单的一个查询语句
    String sqlStatement = "show tables;";

    //加载驱动
    Class.forName(jdbcDriverName);
    try (Connection con = DriverManager.getConnection(connectionUrl)) {
      //查询
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery(sqlStatement);
      System.out.println("---begin query---");

      //打印输出
      while (rs.next()) {
        System.out.println(rs.getString(1));
      }
      System.out.println("---end query---");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
